﻿using System;
using System.Collections.Generic;
using Module.Core.Member;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
using Module.Core.BusinessLogic;
using Module.Core.EntitiesInfo;
using System.Configuration;

namespace Web.Test
{
    public partial class Convert : System.Web.UI.Page
    {
        String strSql = ConfigurationManager.ConnectionStrings["localsql1"].ToString();
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConn = DBUtilEx.OpenConnectionSQL(strSql);
            TreeMemBer tree = new TreeMemBer();
            String sql = "delete from TreeMember";
            DBUtilEx.executeNoneQuery(sqlConn, sql);

            DataTable dt = DBUtilEx.getDataFromSQLServer(sqlConn, "select * from member  order by idMember asc");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
               
                String codeMember = dt.Rows[i]["CodeMember"].ToString().Trim();
                String codeParent = dt.Rows[i]["CodeMemberParent"].ToString().Trim();
                if (codeParent == "0")
                    codeParent = "";
                tree.insertMember(codeMember, codeParent);
            }

            dt = DBUtilEx.getDataFromSQLServer(sqlConn, "select * from upgradeAccount a where exists (select 1 from member  b where b.CodeMember = a.idMember) order by CreatedOn ");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                String codeMember = dt.Rows[i]["idMember"].ToString().Trim();
                tree.upgradeMember(codeMember);
            }
            sqlConn.Close();
        }
    }
}